package pers.richard.ormybatis.util;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;

/**
 *	命名格式转换
 */
public class CaseFormatUtil {
	
	/**
	 * <pre>
	 * AbcXyz == abc_xyz
	 * abcXyz == abc_xyz
	 * abcXyz1 == abc_xyz1
	 * </pre>
	 */
	public static String toLowerUnderscore(String s) {
		//如果全大写和数字
		if (ReUtil.isMatch("[A-Z0-9]+", s)) {
			return s.toLowerCase();
		}
		return StrUtil.toUnderlineCase(s);
	}

	/**
	 * <pre>
	 *	abcXyz == AbcXyz
	 * abc_xyz == AbcXyz
	 * </pre>
	 */
	public static String toUpperCamel(String s) {
		s = toLowerCamel(s);
		return StrUtil.upperFirst(s);
	}
	
	/**
	 * <pre>
	 * AbcXyz == abcXyz
	 * abc_xyz == abcXyz
	 * </pre>
	 */
	public static String toLowerCamel(String s) {
		//如果全大写和数字
		if (ReUtil.isMatch("[A-Z0-9]+", s)) {
			s = s.toLowerCase();
		}
		return StrUtil.toCamelCase(s);
	}
}